/*
 * @Author: 梁青春
 * @Date: 2025-02-20 14:27:00
 * @LastEditTime: 2025-02-20 14:43:09
 * @LastEditors: 梁青春
 */
export const initResizeListener = (options) => {
    const { baseWidth = 1920, baseHeight = 1080 } = { ...options }
    const calcScale = () => {
        const widthRatio = window.innerWidth / baseWidth
        const heightRatio = window.innerHeight / baseHeight
        return Math.min(widthRatio, heightRatio)
    }

    const updateScale = () => {
        const scale = calcScale()
        document.documentElement.style.setProperty('--scale-ratio', scale.toString())
    }

    window.addEventListener('resize', () => {
        requestAnimationFrame(updateScale)
    })

    updateScale()
}